package ch.zhaw.cctd.domain.tower;

import java.awt.Point;
import java.io.Serializable;

import ch.zhaw.cctd.domain.Shootable;
import ch.zhaw.cctd.domain.Shooter;
import ch.zhaw.cctd.domain.map.Map;
import ch.zhaw.cctd.domain.prototype.TowerPrototype.TowerEffectPrototype;

/**
 * Abstrakte TowerEffect Klasse: Bietet Methoden für die Effekt Klassen
 * @author Rolf
 *
 */
public abstract class TowerEffect implements Serializable {
	
	private static final long serialVersionUID = -5004847864480474516L;

	public static enum TowerEffectType {
		SPLASH, SLOW, POISON, CHAIN;
	}

	public TowerEffect(TowerEffectType type, Integer value) {
		this.type = type;
		this.value = value;
	}
	
	public TowerEffect(TowerEffectType type) {
		this(type, 0);
	}
	
	public TowerEffect(TowerEffectPrototype p) {
		this(TowerEffectType.valueOf(p.type.toUpperCase()), p.value);
	}
	
	public final Integer value;
	public final TowerEffectType type;
	
	public abstract void hitEffect(Point hitpoint, Shooter t, Shootable c, Map map);
	
	public static TowerEffect getTowerEffectOfType(TowerEffectPrototype prototype) {
		TowerEffectType type = TowerEffectType.valueOf(prototype.type.toUpperCase());
		switch(type) {
			case SLOW:
				return new SlowTowerEffect(prototype.value);
			case SPLASH:
				return new SplashTowerEffect(prototype.value);
			case CHAIN:
				return new ChainTowerEffect(prototype.value);
			case POISON:
				return new PoisonTowerEffect(prototype.value);
		}
		throw new IllegalArgumentException("unknown type: "+prototype.type);
	}
	
}